Skip to content

chore: add explicit type definitions to consumer arrays and datetime utils#641

Merged
turnipdabeets merged 3 commits into
PostHog:mainfrom
mishrak5j:chore/improve-sdk-type-hints
Jun 2, 2026
Merged

chore: add explicit type definitions to consumer arrays and datetime utils#641
turnipdabeets merged 3 commits into
PostHog:mainfrom
mishrak5j:chore/improve-sdk-type-hints

Conversation

@mishrak5j
Copy link
Copy Markdown
Contributor

💡 Motivation and Context

This PR improves static analysis verification and type safety across utils.py and consumer.py.

  • posthog/utils.py: Added concrete type annotations to foundational datetime utility methods (is_naive, total_seconds, guess_timezone, remove_trailing_slash) to resolve implicit inference gaps and improve IDE auto-completion.
  • posthog/consumer.py: Explicitly typed the background worker's event collection array (items: list[Any] = []) to pass strict static variance checking.

These adjustments eliminate mypy type check errors and improve overall SDK maintainability without introducing runtime performance changes.

💚 How did you test it?

  • Validated via local static type analysis: Checked cleanly using mypy posthog/utils.py.
  • Verified via localized formatting suite: All hooks executed cleanly via pre-commit run.
  • Confirmed runtime stability: Successfully ran the full tracking verification engine with pytest (982 passed).

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

Copilot AI review requested due to automatic review settings June 2, 2026 03:06
@mishrak5j mishrak5j requested a review from a team as a code owner June 2, 2026 03:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds/strengthens type hints in utility and consumer code, improving static analysis and readability.

Changes:

  • Added datetime/timedelta and return/arg type annotations in posthog/utils.py.
  • Added Any import and typed items in Consumer.next().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
posthog/utils.py Adds type annotations for datetime helpers and string utility.
posthog/consumer.py Adds typing for the upload batch list in next().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread posthog/consumer.py
Comment thread posthog/consumer.py
Comment thread posthog/utils.py Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 2, 2026

Reviews (1): Last reviewed commit: "chore: add explicit type definitions to ..." | Re-trigger Greptile

Copy link
Copy Markdown
Contributor

@turnipdabeets turnipdabeets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @mishrak5j

@turnipdabeets turnipdabeets force-pushed the chore/improve-sdk-type-hints branch from e08ce16 to 463cdaf Compare June 2, 2026 15:44
@turnipdabeets turnipdabeets enabled auto-merge (squash) June 2, 2026 15:45
@turnipdabeets turnipdabeets merged commit 20cc088 into PostHog:main Jun 2, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants